/*左边点击中间出现对应的页面*/
$(document).ready(function () {
    // 给左侧菜单栏添加点击事件处理程序
    $("#sidebar .nav a").click(function () {
        let target = $(this).data('target')

        // 隐藏所有页面内容
        $('.page').hide()

        // 显示目标页面内容
        $('#' +  target).show()
    })
    // 显示默认的页面 仪表盘
    $('#dashboard').show()
})
/*选择头像文件js*/
const imageInput = document.getElementById('image-input')
const preview = document.getElementById('preview')

imageInput.addEventListener('change', function (event) {
    const file = event.target.files[0]
    if (file) {
        const reader = new FileReader()
        reader.onload = function (e) {
            preview.src = e.target.result
        }
        reader.readAsDataURL(file)
    } else {
        // 如果没有选择的话，清空文件
        preview.src = ''
    }
})
// 获取年份的起始和结束年份（这里以1900年到当前年份为例）
let startYear = 1900;
let currentYear = new Date().getFullYear();
let endYear = currentYear;

// 填充年份的选项
let yearDropdown = document.getElementById("yyyy");
for (let i = startYear; i <= endYear; i++) {
    let option = document.createElement("option");
    option.text = i;
    option.value = i;
    yearDropdown.add(option);
}

// 填充月份的选项
let monthDropdown = document.getElementById("mm");
for (let i = 1; i <= 12; i++) {
    let option = document.createElement("option");
    option.text = i;
    option.value = i;
    monthDropdown.add(option);
}

// 获取某年某月的最大天数
function getDaysInMonth(year, month) {
    return new Date(year, month, 0).getDate();
}

// 填充日期的选项
let dayDropdown = document.getElementById("dd");
updateDays();

yearDropdown.addEventListener("change", updateDays);
monthDropdown.addEventListener("change", updateDays);

function updateDays() {
    let selectedYear = yearDropdown.value;
    let selectedMonth = monthDropdown.value;
    let maxDays = getDaysInMonth(selectedYear, selectedMonth);

    // 清空原有的选项
    dayDropdown.innerHTML = "";

    // 填充日期的选项
    for (let i = 1; i <= maxDays; i++) {
        let option = document.createElement("option");
        option.text = i;
        option.value = i;
        dayDropdown.add(option);
    }
}
